//公共
import myHeader from "/pages/headerfoot/pages/header.vue"
//公共底部
import Tabbar from "/pages/headerfoot/pages/benefitfooter.vue";
//语言
import Lang from '@/utils/lang.js';
//公共公益方法
import commonBenefit from '@/common/commonbenefit.js';
//公共方法1
import Base from '@/common/base.js';
//骨架
import uniSkeleton from "/plugin/skeleton/components/heaven-skeleton/heaven-skeleton.vue";
//微信api
import weChat from '@/lib/wechat.js';
//cache缓存
import Cache from '@/utils/cache.js';


export default {
	components: {
		Tabbar,
		myHeader,
		uniSkeleton,
	},
	data() {
		return {
			studentzone: Lang.lang.studentzone,
			subject: {},
			loading: true
		}
	},
	onShow() {
		var that = this;
		that.ifreglogin();
		
	},
	methods: {
		//判断是否需要注册或者登录与其他
		async ifreglogin() {
			var that = this;
			var ifreg = 0;
			//注册
			await Base.globalauthorization();

			//判断学生是否注册
			await commonBenefit.ifStudenter().then(res => {
				if (res) {
					uni.redirectTo({
						url: commonBenefit.automaticurl('studentreg')
					})
					ifreg = 1;
				}
			});
			//得到科目信息
			if (ifreg == '0') {
				var data = {};
				data['team_class'] = Cache.get('teamclass'); //年级
				data['school_id'] = Cache.get('schoolid'); //年级
				await commonBenefit.getSubjectListApiMethod(data).then(res => {
					if (res) {
						that.loading = false;
						that.subject = res;
						res.forEach((item, index) => { //js遍历数组
							if (item.subject_name == '语文') {
								Cache.set('subjectId', item.id);
							}
						});
					}
				});
			}

		},
	}
}